package biznussoft.metercor;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import biznussoft.metercor.fragments.ContactDetailsFragment;
import biznussoft.metercor.fragments.StockTransferDetails;
import biznussoft.metercor.fragments.StockTransferLineDetails;
import biznussoft.metercor.fragments.StockTransferLineFragment;
import biznussoft.metercor.listeners.GlobalListener;

public class IInventoryActivty extends BaseActivity implements GlobalListener {

	LinearLayout linear;
	FrameLayout fLayout,stockTransferLine;
	@Override
	protected void onCreate(Bundle savedInstanceState) {             
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_iinventory_activty);
		linear = (LinearLayout) findViewById(R.id.llLayout);
		fLayout= (FrameLayout) findViewById(R.id.viewer);
		stockTransferLine = (FrameLayout) findViewById(R.id.stockTransferLine);
	}



	@Override
	public void onCategoryClicked(final int position) {

		linear.setVisibility(View.VISIBLE);
		fLayout.setVisibility(View.GONE);
		StockTransferDetails newFragment0 = new StockTransferDetails();
		Bundle args = new Bundle();
		args.putInt("Position", position);
		newFragment0.setArguments(args);
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.stocktransferfragmentview, newFragment0);
		transaction.addToBackStack(null);
		transaction.commit();                          


		StockTransferLineFragment newFragment = new StockTransferLineFragment();
		FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction();
		transaction1.replace(R.id.stockTransferLine, newFragment);
		transaction1.commit();
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				StockTransferLineFragment  contactFragment = (StockTransferLineFragment) getSupportFragmentManager().findFragmentById(R.id.stockTransferLine);       
				contactFragment.showContacts(position);
			}
		}, 1000);
	}

	@Override
	public void onServiceClicked(int position) {
		// TODO Auto-generated method stub

		StockTransferDetails newFragment = new StockTransferDetails();
		FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction();
		transaction1.replace(R.id.stocktransferfragmentview, newFragment);
		transaction1.commit();
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				StockTransferDetails  contactFragment = (StockTransferDetails) getSupportFragmentManager().findFragmentById(R.id.stocktransferfragmentview);       
				contactFragment.newStockTransfer();
			}
		}, 1000);




	}

	@Override
	public void onNewContact(String[] args) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onGetContacts(final int position, String category) {
		// TODO Auto-generated method stub
		linear.setVisibility(View.GONE);
		fLayout.setVisibility(View.VISIBLE);
		StockTransferLineDetails newFragment = new StockTransferLineDetails();
		FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
		transaction.replace(R.id.viewer, newFragment);
		transaction.addToBackStack(null);
		transaction.commit();

		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				StockTransferLineDetails  contactFragment = (StockTransferLineDetails) getSupportFragmentManager().findFragmentById(R.id.viewer);       
				contactFragment.stockTransferDetails(position);
			}
		}, 1000);


	}

	@Override
	public void getSignature(String base64) {
		// TODO Auto-generated method stub
		stockTransferLine.setVisibility(View.GONE);
	}

	@Override
	public void displayFields(int position, String category) {
		// TODO Auto-generated method stub

	}

}
